<?php
/**
 * Created by JetBrains PhpStorm.
 * User: xiaoyanore
 * Date: 2015-5-4
 * Time: 下午1:47
 * To change this template use File | Settings | File Templates.
 */
require 'libs/XYRouter/YCLoader.php';
YCLoader::init()->loadUserLib(array(
    'application/common/Base.php',
    'application/common/BaseController.php',
    'application/common/Util.php',
    'application/common/RetMessage.php'
)); // 初始化
RouterCore::getInstance()
    ->setRunMode(RunMode::DEV)
    ->init('/libs/conf.php')
    ->invoke(function(){
        $r = RouterCore::getInstance();
        $twig = $r->getTwig();
        $twig->addFunction("__FieldTypeName__",new Twig_Function_Function("getFieldTypeName"));
        $twig->addFunction("DataState",new Twig_Function_Function("dataState"));
        $twig->addFunction("NoticeState",new Twig_Function_Function("noticeState"));
        $twig->addFunction("TaskState",new Twig_Function_Function("taskState"));
        $twig->addFunction("UserPermission",new Twig_Function_Function("permission"));
        $twig->addFunction("HasPermission",new Twig_Function_Function("hasPermission"));
    })
    ->beforeInterceptor(function(){
        $path = RouterCore::getInstance()->getPath();
        if(!isset($_SESSION['osw_uid']) || $_SESSION['osw_uid'] < 0){
            if(!in_array($path,array(
                '/user.view.login','/user.action.login'
            ))){
                if(isAjax()){
                    ajaxResponse(403,'登录信息失效','user.view.login');
                }
                echo '<html><head><meta http-equiv="refresh" content="0;url=user.view.login"></head></html>';
                exit;
            }
        }
    })
    ->dispatch();